package 力扣日常刷题.木22一月.第15天0127;

import java.util.Stack;

/**
 * @author 帅小伙
 * @date 2022/1/27
 * @description
 */
public class Demo10JZ30包含main函数的栈 {

    class MinStack {

        Stack<Integer> stack;
        Stack<Integer> min;

        public MinStack() {
            stack = new Stack<>();
            min = new Stack<>();
        }

        public void push(int x) {
            stack.push(x);
            if (min.isEmpty() || min.peek() >= x) min.push(x);
        }

        public void pop() {
            /*
            * 这个才堆  不知道为什么
            int a = stack.peek();
            int b = min.peek();
            if ( a == b){
                min.pop();
            }
            * */
            if (stack.peek() == min.peek()){
                min.pop();
            }
            stack.pop();
        }

        public int top() {
            return stack.peek();
        }

        public int min() {
            return min.peek();
        }
    }

}
